package com.CampusLife.controller;
import	java.util.ArrayList;

import com.CampusLife.bean.*;
import com.CampusLife.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/index")
public class IndexController {
    @Resource
    private IProductService iproductService;
    @Resource
    private ILostProductService iLostProductService;
    @Resource
    private INewsService iNewsService;
    @Resource
    private  IPictureService iPictureService;
    @Resource
    private IProductTypeService iProductTypeService;
    @RequestMapping("/ToIndex")
    public String ToIndex(Model model, HttpSession httpSession){
        List<Product> products=iproductService.getOrder();
        List<LostProduct>  lostProducts=iLostProductService.getOrder();
        List<News> news=iNewsService.getOrder();
        List<Picture> pictures=iPictureService.getIndex();
        String username=(String) httpSession.getAttribute("name");
        model.addAttribute("products",products);
        model.addAttribute("lostProducts",lostProducts);
        model.addAttribute("news",news);
        model.addAttribute("username",username);
        model.addAttribute("picture",pictures);
        return "home/home";
    }
    @RequestMapping("/product")
    public  String  product(Model model) {
        List<ProductType> top =iProductTypeService.queryATop ();
        model.addAttribute("top", top);
        List<ProductType>  end =iProductTypeService.queryEnd ();
        model.addAttribute("end", end);
        List<Picture> pictures=iPictureService.getShop();
        model.addAttribute("pictures", pictures);
        return "home/product";
    }
}
